#ifndef _SIMPLE_STROKE_OPTMIZER_H
#define _SIMPLE_STROKE_OPTMIZER_H


//#include "mathlib.h"
#include "stdafx.h"
#include <vector>


class GridField;
class DecoArticulatedObject;
class FLuidSparseMatrix;
class CSRMatrix;
class DecoScene;


class SimpleStrokeOptimizer
{
public:
	SimpleStrokeOptimizer(DecoScene* scene);
	~SimpleStrokeOptimizer();
	void SetWeights(const std::vector<double>& weights);
	void SetFluidField(GridField* field);
	void SetDesiredDirection(const vector3& dir);
	double GetOptimalQDot(double timeStep, std::vector<double>& qdot);
	void SetMatrices(CSRMatrix* csrMat, FLuidSparseMatrix* fluidMat);
private:
	double optimize(double timeStep, std::vector<double>& qdot);
	void calculateFMatrix(double timeStep);
	void calculateBMatrix(double timeStep);
	double calculateOptimalValue(const std::vector<double>& qdot);
	void clear();
	DecoArticulatedObject* getArticulatedObject();
	GridField* mGrid;
	std::vector<double> mWeights;
	vector3 mDesiredDir;
	double** mB;
	double** mF;
	double** mTmp;
	double* mRhs;
	DecoScene* mScene;
	CSRMatrix* mCSRMat;
	FLuidSparseMatrix* mFluidMat;
};


#endif